/**
 *  Copyright 2010 ShenYang voole Co. Ltd.
 *  All right reserved. 
 */
package com.dianning.dao.hibernate;


import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dianning.bean.AdAds;
import com.dianning.bean.AdSpace;
import com.dianning.bean.Admin;
import com.dianning.bean.Area;
import com.dianning.bean.Channel;
import com.dianning.bean.Company;
import com.dianning.bean.Visitor;
import com.dianning.comm.Constant;
import com.dianning.dao.AdAdsDAO;
import com.dianning.dao.AdSpaceDAO;
import com.dianning.dao.AdminDAO;
import com.dianning.dao.AreaDAO;
import com.dianning.dao.ChannelDAO;
import com.dianning.dao.CompanyDAO;
import com.dianning.dao.VisitorDAO;

/**
 * 功能描述:公司操作实现
 *
 * 创建日期 Apr 10, 2010
 *
 * @author zhangbaochao
 *
 * @version 1.0
 *
 */
public class CompanyHibernateDAO extends HibernateDaoSupport implements CompanyDAO {

	private static final String LOAD_BY_UID = "from Company where uid = ?";
	
	/**
	 * 保存Company对象
	 * 
	 * @param company
	 * 			Company对象
	 * @return Company
	 * 			Company对象
	 */
	public Company saveCompany(Company company){
		this.getHibernateTemplate().save(company);
		return company;
	}
	/**
	 * 保存或更新Company对象
	 * 
	 * @param company
	 * 			Company对象
	 * @return Company
	 * 			Company对象
	 */
	public Company saveOrUpdateCompany(Company company){
		this.getHibernateTemplate().saveOrUpdate(company);
		return company;
	}
	/**
	 * 保存Company对象
	 * 
	 * @param company
	 * 			Company对象
	 * @return Company
	 * 			Company对象
	 */
	public Company updateCompany(Company company){
		this.getHibernateTemplate().update(company);
		return company;
	}
	
	/**
	 * 根据主键ID获取Company对象
	 * 
	 * @param uid
	 * 			主键ID
	 * @return Company
	 * 			Company对象
	 */
	public Company findCompanyByUid(long uid){
		List l = this.getHibernateTemplate().find(LOAD_BY_UID,uid);
		if(l == null || l.isEmpty()){
			return null;
		}else{
			return (Company) l.get(0);
		}
	}
}
